﻿using winS.Unity.Process;
using winS.UnityEditor.UIElement;

namespace winS.UnityEditor.ProcessEditor
{
    [Title("全通后输出", "All Pass"), StepNodeSearchTreeGroup("内置/全通后输出")]
    public class AllPassStepNode : GeneralStepNode<AllPassStep>
    {
        private IntField intField;

        protected internal override void OnCreated()
        {
            inputPort.onConnected += OnConnected;
            inputPort.onDisconnected += OnDisconnected;
            Add(intField = guiFactory.CreateIntField("已连接数:", step.passCount));
            intField.SetEnabled(false);
        }

        protected internal override void OnReady()
        {
            step.passCount = inputPort.connectedCount;
            intField.SetValueWithoutNotify(step.passCount);
        }

        private void OnConnected(Port inputPort)
        {
            step.passCount++;
            intField.SetValueWithoutNotify(step.passCount);
        }
        private void OnDisconnected(Port inputPort)
        {
            step.passCount--;
            intField.SetValueWithoutNotify(step.passCount);
        }
    }
}